package cn.anecansaitin.whimsy.common.network;

import cn.anecansaitin.whimsy.Whimsy;
import cn.anecansaitin.whimsy.common.attachment.SpeedData;
import cn.anecansaitin.whimsy.common.register.ModDataAttachments;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.neoforge.network.handling.PlayPayloadContext;

public record ClientRocketPunchStopPack() implements CustomPacketPayload {
    public static final ResourceLocation ID = Whimsy.resource("client_rocket_punch_stop_pack");
    public static final ClientRocketPunchStopPack.ClientHandler CLIENT_HANDLER = new ClientRocketPunchStopPack.ClientHandler();

    public ClientRocketPunchStopPack(FriendlyByteBuf buffer) {
        this();
    }

    @Override
    public void write(FriendlyByteBuf buffer) {

    }

    @Override
    public ResourceLocation id() {
        return ID;
    }

    public static class ClientHandler {
        private ClientHandler() {}

        public void handle(ClientRocketPunchStopPack data, PlayPayloadContext context) {
            context.workHandler().submitAsync(() -> {
                LocalPlayer player = Minecraft.getInstance().player;
                SpeedData rocketPunchData = player.getData(ModDataAttachments.SPEED_DATA);
                rocketPunchData.isNull = true;
            });
        }
    }
}
